package com.ititer;

import org.springframework.beans.BeanUtils;

import com.ititer.web.Bean;
import com.ititer.web.ValidationResult;

public abstract class AbstractBean implements Bean, Cloneable {

	private static final long serialVersionUID = -4171913779907105538L;

	//TODO: implements
	@Override
	public ValidationResult validate() {
		return null;
	}

	@Override
	public Bean bindFrom(Object... objects) {
		for (Object object : objects) {
			BeanUtils.copyProperties(object, this);
		}
		return this;
	}

	@Override
	public void bindTo(Object... objects) {
		for (Object object : objects) {
			BeanUtils.copyProperties(this, object);
		}
	}

	@Override
	public <T> T bindTo(Class<T> clazz) {
		try {
			T object = clazz.newInstance();
			bindTo(object);
			return object;
		} catch (InstantiationException e) {
			e.printStackTrace();
		} catch (IllegalAccessException e) {
			e.printStackTrace();
		}
		return null;
	}

}
